<!--
*  功能描述：绩效管理：考核任务
 -->
<template>
  <div class="page">
    <el-row>
      <el-col :span="14">
        <div class="grid-content bg-purple-dark">
          <el-row>
            <el-col :span="24">
              <div class="grid-content bg-purple-dark">
                <div class="zuoshang">
                  <div style="
                      float: left;
                      background-color: DodgerBlue;
                      width: 100%;
                      color: white;
                    ">
                    <span>考核列表</span>
                    <span style="float: right">
                      <el-button size="mini" style="background-color: red; color: white" @click="Assessments">
                        新建任务
                      </el-button>
                    </span>
                  </div>
                  <template>
                    <el-table :data="tableData" style="width: 100%; text-align: center">
                      <el-table-column prop="AssId" label="任务编号">
                      </el-table-column>
                      <el-table-column prop="AssCreateTime" label="建立时间">
                      </el-table-column>
                      <el-table-column label="起始-截止时间">
                        <template>
                          <el-table-column prop="AssStartTime" label="起始时间" width="125px"></el-table-column>
                          <el-table-column prop="AssEndTime" label="截止时间" width="125px"></el-table-column>
                        </template>
                      </el-table-column>
                      <el-table-column prop="AssProject" label="项目考核" width="70px">
                        <template slot-scope="scope">
                          <el-button size="mini" @click="xiangmutz(scope.row.AssId)">
                            {{scope.row.AssProject}}
                          </el-button>
                        </template>
                      </el-table-column>
                      <el-table-column prop="AssDepartment" label="部门考核" width="70px">
                        <template slot-scope="scope">
                          <el-button size="mini">
                            {{scope.row.AssDepartment}}
                          </el-button>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button v-if="scope.row.AssFile == false" size="mini"
                            @click="EditAssessment(scope.row.AssId)">修改</el-button>
                          <el-button v-else size="mini" disabled>修改
                          </el-button>
                          <el-button v-if="scope.row.AssFile == false" size="mini" @click="
                              DeleteAssessment(scope.row.AssId)
                            ">删除</el-button>
                          <el-button v-else size="mini" disabled>删除</el-button>
                        </template>
                      </el-table-column>
                      <el-table-column label="归档">
                        <template slot-scope="scope">
                          <el-button size="small" v-if="scope.row.AssFile == false" @click="
                              GetInspectionUpdateGd(scope.row.AssId)
                            ">归档</el-button>
                          <el-button size="small" v-else @click="
                              GetInspectionUpdateGd(scope.row.AssId)
                            " disabled>已归档</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </template>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="grid-content bg-purple-dark">
                <div class="zuoxia">
                  <div style="
                      float: left;
                      background-color: DodgerBlue;
                      width: 100%;
                      color: white;
                    ">
                    <span>考核统计</span>
                  </div>
                  <template>
                    <el-table :data="tableData" style="width: 100%">
                      <el-table-column prop="AssId" label="考核任务">
                      </el-table-column>
                      <el-table-column label="技术部门(非股东)项目奖金+部门内奖金(元)">
                        <template>
                          <el-table-column prop="AssValue" label="实际发放/系统计算值">
                          </el-table-column>
                          <el-table-column prop="AssEntry" label="初始录入">
                          </el-table-column>
                        </template>
                      </el-table-column>
                      <el-table-column prop="AssTotalWages" label="技术部门(非股东)平均月工资合计(元)">
                      </el-table-column>
                      <el-table-column prop="AssAvgWages" label="奖金基数=(项目奖金+部门内奖金)/平均月工资">
                      </el-table-column>
                    </el-table>
                  </template>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-col>
      <el-col :span="9">
        <div class="grid-content bg-purple-dark">
          <el-row style="margin-left: 30px">
            <el-col :span="24">
              <div class="grid-content bg-purple-dark">
                <div class="youshang">
                  <div class="dingtou" style="
                      width: 100%;
                      border: 1px solid;
                      background-color: dodgerblue;
                      color: white;
                    ">
                    <span>任务编辑</span>
                  </div>
                  <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="任务编号" style="width: 300px">
                      <el-input v-model="form.AssId"></el-input>
                    </el-form-item>
                    <el-form-item label="起始时间">
                      <el-date-picker type="date" v-model="form.AssStartTime"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="截止时间">
                      <el-date-picker type="date" v-model="form.AssEndTime"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="备注" style="width: 300px">
                      <el-input v-model="form.AssBeiZhu"></el-input>
                    </el-form-item>
                    <el-form-item label="项目考核">
                      <el-select v-model="form.AssProject">
                        <el-option label="进行中" value="进行中"></el-option>
                        <el-option label="已暂停" value="已暂停"></el-option>
                        <el-option label="已完成" value="已完成"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="部门考核">
                      <el-select v-model="form.AssDepartment">
                        <el-option label="进行中" value="进行中"></el-option>
                        <el-option label="已暂停" value="已暂停"></el-option>
                        <el-option label="已完成" value="已完成"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item>
                      <el-show v-if="addshow">
                        <el-button type="primary" @click="PostAssessmentList">添加</el-button>
                      </el-show>
                    </el-form-item>
                    <el-form-item>
                      <el-show v-if="updateass">
                        <el-button type="primary" @click="updateAssessmentList">保存</el-button>
                      </el-show>
                    </el-form-item>
                  </el-form>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      data: [],
      form: {//添加任务编辑
        AssId: '',
        AssStartTime: '',
        AssEndTime: '',
        AssBeiZhu: '',
        AssProject: '',
        AssDepartment: '',
        AssValue: 0,
        AssEntry: 0,
        AssTotalWages: 0,
        AssAvgWages: 0,
      },
      addshow: false,
      updateass: false,
      dialogVisible: false,
    };
  },
  methods: {
    PostAssessmentList () {//添加任务编辑 
      if (this.form.AssId == undefined) {
        alert('任务编号不能为空');
        return;
      }
      this.$http({
        url: 'Assessment/AddAssessmentList',
        method: 'post',
        data: this.form
      })
        .then(res => {
          if (res.data > 0) {
            this.$message.success('任务添加成功')
            this.showAssessmentList();
          }
        })
    },
    showAssessmentList () {//显示考核列表
      this.$http({
        url: 'Assessment/GetAssessmentList',
        method: 'get',
      })
        .then(res => {
          this.tableData = res.data
        })
    },
    EditAssessment (id) {//任务编辑反填
      this.updateass = true;
      this.addshow = false;
      this.$http({
        url: 'Assessment/GetAssessmentListFT',
        method: 'get',
        params: {
          id: id
        }
      })
        .then(res => {
          this.form = res.data
        })
    },
    Assessments () {//显示添加
      this.form = {},
        this.addshow = true;
      this.updateass = false;
    },
    updateAssessmentList () {//修改任务编辑
      this.$http({
        url: 'Assessment/PutAssessmentList',
        method: 'put',
        data: this.form
      })
        .then(res => {
          if (res.data > 0) {
            this.$message.success('任务修改成功')
            this.showAssessmentList();
          }
        })
    },
    DeleteAssessment (ids) {//删除考核列表
      if (confirm('确定删除吗？')) {
        this.$http({
          url: 'Assessment/DeleteAssessmentList',
          method: 'delete',
          params: {
            id: ids
          }
        })
          .then(res => {
            if (res.data > 0) {
              this.$message.success('删除成功')
              this.showAssessmentList();
            }
          })
      }
    },
    GetInspectionUpdateGd (id) {//归档
      if (confirm('确定归档吗？')) {
        this.$http({
          url: 'Assessment/PostAssessmentList',
          method: 'post',
          params: {
            id: id
          }
        })
          .then(res => {
            if (res.data > 0) {
              this.$message.success('归档成功')
              this.showAssessmentList();
            }
          })
      }

    },
    xiangmutz (id) {
      this.$router.push({
        path: '/AssmentProject',
        name: 'AssmentProject',
        params: {
          id: id
        }
      })
    }

  },
  created () {
    this.showAssessmentList();
  },
};
</script>

<style>
.zuoshang {
  width: 100%;
  float: left;
  border: 1px solid;
}
.zuoxia {
  width: 100%;
  margin-top: 30px;
  float: left;
  border: 1px solid;
}
.youshang {
  width: 100%;
  float: right;
  border: 1px solid;
  margin-left: 50px;
}
</style>